/**
 *
 * @param {请求类型} method
 * @param {请求路径} url
 * @param {请求参数} params
 * @param {请求参数} params
 * @param {
   json = true， 'Content-type': 'application/x-www-form-urlencoded'
   json = false， 'Content-type': 'applicaiton/json;'
 }
 json
 */
import Vue from 'vue'
let http = (method = 'get', url, params, json = false) => {
  method = method.toLocaleLowerCase();
  let data = {};
  if (method !== 'get') {
    data = params;
    params = {};
  }
  var httpPromise = null;
  if (!httpPromise) {
    httpPromise = new Promise((resolve, reject) => {
      Vue.prototype.$axios({
        method,
        url,
        params,
        data,
        transformRequest: [
          function(data) {
            if (!json) {
              let ret = [];
              for (let it in data) {
                ret.push(
                  encodeURIComponent(it) + '=' + encodeURIComponent(data[it])
                );
              }
              return ret.join('&');
            } else {
              return data;
            }
          }
        ],
        timeout: 6000
      })
        .then(res => {
          if (res.data.success) {
            resolve(res.data);
          } else {
            reject(res.data);
          }
        })
        .catch(res => {
          reject(res.data);
        });
    });
  }
  return httpPromise;
};

// 视频监控
// 企业端
// 按区域获取企业下视频监控统计列表
export const getEntryVideoListByRegion = (
  params,
  url =  `${Vue.prototype.$site.videoServer}/api/enterpriseWebVideoController/getEntryVideoListByRegion`,
) => http('post', url, params);

// 按项目获取企业下或区域下视频监控统计列表
export const getEntryVideoListByProject = (params,
  url = `${Vue.prototype.$site.videoServer}/api/enterpriseWebVideoController/getEntryVideoListByProject`
  ) => http('post', url, params);

// 获取未接入项目统计
export const getNoAccessProjectCount = (params,
  url = `${Vue.prototype.$site.videoServer}/api/enterpriseWebVideoController/getNoAccessProjectCount`
  ) => http('post', url, params);

// 获取未接入项目列表
export const getNoAccessProjectList = (params,
  url = `${Vue.prototype.$site.videoServer}/api/enterpriseWebVideoController/getNoAccessProjectList`,
  ) => http('post', url, params);

// 获取用户可选区域列表
export const getDepartmentList = (params,
  url = `${Vue.prototype.$site.videoServer}/api/enterpriseWebVideoController/getDepartmentList`
  ) => http('post', url, params);

// 项目端
// 根据项目id获取项目下设备列表
export const getProjectVideoList = (params,
  url = `${Vue.prototype.$site.videoServer}/api/projectWebVideoController/getProjectVideoList`
  ) => http('post', url, params);

// 获取项目下报警/预警统计信息
export const getProjectVideoCatchCount = (params,
  url = `${Vue.prototype.$site.videoServer}/api/projectWebVideoController/getProjectVideoCatchCount`
  ) => http('post', url, params);

// 获取项目下设备报警记录
export const getProjectVideoCatchList = (params,
  url = `${Vue.prototype.$site.videoServer}/api/projectWebVideoController/getProjectVideoCatchList`
  ) => http('post', url, params);

// 根据探头uuid获取直播预览参数
export const getPreviewParam = (params,
  url = `${Vue.prototype.$site.videoServer}/api/projectWebVideoController/getPreviewParam`
  ) => http('post', url, params);

// 根据探头uuid获取回放预览参数
export const getPlaybackParamByPlanUuid = (params,
  url = `${Vue.prototype.$site.videoServer}/api/projectWebVideoController/getPlaybackParamByPlanUuid`
  ) => http('post', url, params);

// 根据探头id上移/下移设备
export const updateDeviceVideoPriority = (params,
  url = `${Vue.prototype.$site.videoServer}/api/projectWebVideoController/updateDeviceVideoPriority`
  ) => http('post', url, params);

// 获取项目下标段对应设备列表
export const getDeviceVideoListByTenders = (params,
  url = `${Vue.prototype.$site.videoServer}/api/projectWebVideoController/getDeviceVideoListByTenders`
  ) => http('post', url, params);

// 根据8700中心uuid获取区域列表
export const getRegionsByUnitUuid = (params,
  url = `${Vue.prototype.$site.videoServer}/api/projectWebVideoController/getRegionsByUnitUuid`
  ) => http('post', url, params);

// 根据页面提供的 项目-分期-标段-设备级联对象 更新项目下视频监控设备
export const updateDeviceVideoListByUnit = (params,
  url = `${Vue.prototype.$site.videoServer}/api/projectWebVideoController/updateDeviceVideoListByUnit`
  ) => http('post', url, params);




// 塔吊监控
// 企业级设备监控率统计
export const getDeviceMonitor = (params,
  url = `${Vue.prototype.$site.videoServer}/api/towercrane/getDeviceMonitor`
  ) => http('post', url, params);

// 企业级设备列表
export const getComTowerByArea = (params,
  url = `${Vue.prototype.$site.videoServer}/api/towercrane/getComTowerByArea`
  ) => http('post', url, params);

// WEB端 - 项目级设备列表
export const getComTowerByProject = (params,
  url = `${Vue.prototype.$site.videoServer}/api/towercrane/getComTowerByProject`
  ) => http('post', url, params);

// 今日塔吊报警 - 全集团
export const getComTodayTowerAlarm = (params,
  url = `${Vue.prototype.$site.videoServer}/api/towercrane/getComTodayTowerAlarm`
  ) => http('post', url, params);

// 无塔吊项目列表
export const noMonitorList = (params,
  url = `${Vue.prototype.$site.videoServer}/api/towercrane/noMonitorList`
  ) => http('post', url, params);

// 项目级塔吊监控列表（字段无数据则为null）
export const getMonitorList = (params,
  url = `${Vue.prototype.$site.videoServer}/api/towercrane/getMonitorList`
  ) => http('post', url, params);

// 项目级塔吊监控列表（字段无数据则为null）
export const getTowerAlarmLastWeek = (params,
  url = `${Vue.prototype.$site.videoServer}/api/towercrane/getTowerAlarmLastWeek`
  ) => http('post', url, params);

// 设备工作记录 - 塔吊今日吊次
export const getTowercraneWorkDataByDay = (params,
  url = `${Vue.prototype.$site.videoServer}/api/towercrane/getTowercraneWorkDataByDay`
  ) => http('post', url, params);

// 设备工作记录 -工作记录总数和有效工作时长
export const towerWorkNumWorkTime = (params,
  url = `${Vue.prototype.$site.videoServer}/api/towercrane/towerWorkNumWorkTime`
  ) => http('post', url, params);

// 综合分析/单机分析
export const getTowercraneMonitorAnalysis = (params,
  url = `${Vue.prototype.$site.videoServer}/api/towercrane/getTowercraneMonitorAnalysis`
  ) => http('post', url, params);

// 设备信息维护-新增
export const elevatorInfoMaintain = (params,
  url = `${Vue.prototype.$site.videoServer}/api/device/elevatorInfoMaintain`
  ) => http('post', url, params);

// 更新设备状态
export const updateElevatorStatus = (params,
  url = `${Vue.prototype.$site.videoServer}/api/device/updateElevatorStatus`
  ) => http('post', url, params);

// web端获取监控列表
export const getGroupRefer = (params,
  url = `${Vue.prototype.$site.videoServer}/api/device/getGroupRefer`
  ) => http('post', url, params);

// 查看设备档案
export const getTowerDevice = (params,
  url = `${Vue.prototype.$site.videoServer}/api/device/getDevice`
  ) => http('post', url, params);

// 设备自编号列表
export const getCodeList = (params,
  url = `${Vue.prototype.$site.videoServer}/api/device/getCodeList`
  ) => http('post', url, params);

// 获取区域列表
export const getTowerDepartmentList = (params,
  url = `${Vue.prototype.$site.videoServer}/api/towercrane/getDepartmentList`
  ) => http('post', url, params);

// 导出企业级
export const getComTowerByProjectExport = (params,
  url = `${Vue.prototype.$site.videoServer}/api/towercrane/getComTowerByProjectExport`
  ) => http('post', url, params);




// 环境监测
// 按照区域/城市公司的维度查询
export const getEnvInfoByArea = (params,
  url = `${Vue.prototype.$site.videoServer}/api/environmentMonitor/getInfoByArea`
  ) => http('post', url, params);

// 带有数据权限（部门数据表经过数据过滤）的区域
export const getEnvRegionInfo = (params,
  url = `${Vue.prototype.$site.videoServer}/api/environmentMonitor/getRegionInfo`
  ) => http('post', url, params);

// 按照项目的维度查询
export const getEnvInfoByProject = (params,
  url = `${Vue.prototype.$site.videoServer}/api/environmentMonitor/getInfoByProject`
  ) => http('post', url, params);

// 无监测的项目，指的是无关联监测设备的项目 PS:只按照区域的维度来查询的数据集合
export const getNoneEnvMonitorDeviceProject = (params,
  url = `${Vue.prototype.$site.videoServer}/api/environmentMonitor/getNoneMonitorDeviceProject`
  ) => http('post', url, params);

// 项目的一些参数阈值的设置，新增或者编辑参数阈值
export const setThreshold = (params,
  url = `${Vue.prototype.$site.videoServer}/api/environmentMonitor/setThreshold`
  ) => http('post', url, params);

// 监测点信息，按照项目维度，查询一个项目下所有监测点信息，一个监测点对应一个设备（包含离线设备）
export const getMonitorInfo = (params,
  url = `${Vue.prototype.$site.videoServer}/api/environmentMonitor/getMonitorInfo`
  ) => http('post', url, params);

// 某个项目某个监测点下面环境监测相关的数据 环境监测
export const getEnvirMonitorInfo = (params,
  url = `${Vue.prototype.$site.videoServer}/api/environmentMonitor/getEnvirMonitorInfo`
  ) => http('post', url, params);

// 某个项目，天气预报相关的数据（今天和未来三天的天气数据）
export const getWeatherForecastInfo = (params,
  url = `${Vue.prototype.$site.videoServer}/api/environmentMonitor/getWeatherForecastInfo`
  ) => http('post', url, params);

// 统计一个项目下的一个设备近7天的扬尘和噪音每天的平均值
export const getDeviceDustDataLastSevenDay = (params,
  url = `${Vue.prototype.$site.videoServer}/api/environmentMonitor/getDeviceDustDataLastSevenDay`
  ) => http('post', url, params);

// 查看更多统计
export const getDeviceDustWorkSum = (params,
  url = `${Vue.prototype.$site.videoServer}/api/environmentMonitor/getDeviceDustWorkSum`
  ) => http('post', url, params);

// 获取阈值
export const getThresholdList = (params,
  url = `${Vue.prototype.$site.videoServer}/api/environmentMonitor/getThresholdList`
) => http('post', url, params);

// 按照区域/城市公司的维度查询导出
export const getInfoByAreaExcel = (params,
  url = `${Vue.prototype.$site.videoServer}/api/environmentMonitor/getInfoByAreaExcel`
  ) => http('post', url, params);

// 按照项目的维度查询导出
export const getInfoByProjectExcel = (params,
  url = `${Vue.prototype.$site.videoServer}/api/environmentMonitor/getInfoByProjectExcel`
  ) => http('post', url, params);

// 无监测的项目查询导出
export const getNoneMonitorDeviceProjectExcel = (params,
  url = `${Vue.prototype.$site.videoServer}/api/environmentMonitor/getNoneMonitorDeviceProjectExcel`
  ) => http('post', url, params);




// 升降机监控
// 企业级设备监控率统计
export const getElevatorDeviceMonitor = (params,
  url = `${Vue.prototype.$site.videoServer}/api/elevator/getElevatorDeviceMonitor`
  ) => http('post', url, params);

// 企业级设备列表
export const getComElevatorByArea = (params,
  url = `${Vue.prototype.$site.videoServer}/api/elevator/getComElevatorByArea`
  ) => http('post', url, params);

// WEB端 - 项目级设备列表
export const getComElevatorByProject = (params,
  url = `${Vue.prototype.$site.videoServer}/api/elevator/getComElevatorByProject`
  ) => http('post', url, params);

// 今日升降机报警 - 全集团
export const getComTodayElevatorAlarm = (params,
  url = `${Vue.prototype.$site.videoServer}/api/elevator/getComTodayElevatorAlarm`
  ) => http('post', url, params);

// 无升降机项目列表
export const getNoElevatorProject = (params,
  url = `${Vue.prototype.$site.videoServer}/api/elevator/getNoElevatorProject`
  ) => http('post', url, params);

// 项目级升降机监控列表（字段无数据则为null）
export const getElevatorMonitorList = (params,
  url = `${Vue.prototype.$site.videoServer}/api/elevator/getElevatorMonitorList`
  ) => http('post', url, params);

// 近7天升降机监控报警统计（无数据则为0）
export const getElevatorAlarmLastWeek = (params,
  url = `${Vue.prototype.$site.videoServer}/api/elevator/getElevatorAlarmLastWeek`
  ) => http('post', url, params);

// 设备工作记录 - 升降机今日吊次
export const getElevatorWorkDataByDay = (params,
  url = `${Vue.prototype.$site.videoServer}/api/elevator/getElevatorWorkDataByDay`
  ) => http('post', url, params);

// 设备工作记录 -工作记录总数和有效工作时长
export const elevatorWorkNumWorkTime = (params,
  url = `${Vue.prototype.$site.videoServer}/api/elevator/elevatorWorkNumWorkTime`
  ) => http('post', url, params);

// 综合分析/单机分析
export const elevatorAnalyze = (params,
  url = `${Vue.prototype.$site.videoServer}/api/elevator/elevatorAnalyze`
  ) => http('post', url, params);

// 获取区域列表
export const getElevatorDepartmentList = (params,
  url = `${Vue.prototype.$site.videoServer}/api/elevator/getDepartmentList`
  ) => http('post', url, params);
